#include "read_options.h"
namespace po = boost::program_options;
using std::vector;
using std::string;

#include <boost/format.hpp>
		using boost::format;

bool read_options(prog_options& opt, int argc, char *argv[])
{
	opt.mandatory.add_options()
								("input_file,i",po::value<std::string>(&opt.input_file_name)
										//->set_name("FILE"),
										,"SNPs in tab delimited format.<contig><pos><category>. "
										 "The last column is optional. See --intervals_only")
								("interval_file,I",po::value<vector<string> >(&opt.interval_file_names)
										//->set_name("FILE"),
										,"In tab delimited format <contig><start><end>. ")
								("interval_type,T",po::value<vector<string> >(&opt.interval_type_names)
										//->set_name("FILE"),
										,"Corresponding type for each interval file. ")
								("default_type,D",po::value<std::string>(&opt.default_interval_type_name)
										//->set_name("FILE"),
										,"Type of SNPs outside all intervals.")
								("contig_sizes_file,C",po::value<string>(&opt.contig_sizes_file_name)
										//->set_name("FILE"),
										,"In tab delimited format <contig><beg><end>.");



	opt.optional.add_options()
								("jobs,j",po::value<unsigned>(&opt.jobs)
										->default_value(20)
										,"Allow N jobs to run in parallel at the same time.")
								("intervals_only",po::value<bool>(&opt.intervals_only)
										->zero_tokens()
										,"Only categorise by interval type.")
								("zero_based_snps,Z",po::value<bool>(&opt.zero_based_snps)
										->zero_tokens()
										,"SNP positions specified in zero based [) coordinates (UCSC) rather than 1-based [] (Ensembl).")
								("zero_based_intervals,z",po::value<bool>(&opt.zero_based_intervals)
										->zero_tokens()
										,"Intervals specified in zero based [) coordinates (UCSC) rather than 1-based [] (Ensembl).");
								


	
	opt.config_file.add_options()
								("input_file,i",           po::value<std::string>      	(&opt.input_file_name            ))  
								("interval_file,I",        po::value<vector<string> >  	(&opt.interval_file_names        ))  
								("interval_type,T",        po::value<vector<string> >  	(&opt.interval_type_names        ))  
								("contig_sizes_file,C",	   po::value<string>		   	(&opt.contig_sizes_file_name	 ))
								("default_type,D",         po::value<std::string>      	(&opt.default_interval_type_name ))  
								("intervals_only",         po::value<bool>             	(&opt.intervals_only             ))  
								("jobs,j",                 po::value<unsigned>         	(&opt.jobs                       ))  
								("zero_based_snps,Z",      po::value<bool>             	(&opt.zero_based_snps            ))  
								("zero_based_intervals,z", po::value<bool>             	(&opt.zero_based_intervals       )); 


	if (!opt.process_command_line(argc, argv))
		return false;

	// check number of interval types and file names match
	if (opt.interval_type_names.size() != opt.interval_file_names.size())
		throw std::runtime_error((boost::format("The number of --interval_file (%1$)"
												"should match the number of "
												"--interval_type (%2$)") 
												% opt.interval_file_names.size()
												% opt.interval_type_names.size()).str());

	opt.verbose() << "\n\n";
	return true;
}



